from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String, func
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsCar(Base):
    __tablename__ = 'cms_car'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='_copy_14'),
        {'comment': '车辆信息'}
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    car_id: Mapped[str] = mapped_column(String(32), comment='车辆编码')
    car_number: Mapped[str] = mapped_column(String(32), comment='车牌号')
    car_department_id: Mapped[str] = mapped_column(String(32), comment='所属部门id')
    car_team_id: Mapped[str] = mapped_column(String(32), comment='车队id')
    device_id: Mapped[str] = mapped_column(String(32), comment='设备id')
    state: Mapped[int] = mapped_column(Integer, comment='状态（0 失效，1 有效）')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, comment='创建时间', server_default=func.now())
    car_image: Mapped[Optional[str]] = mapped_column(String(255), comment='车辆照片')
    car_permit_image: Mapped[Optional[str]] = mapped_column(String(255), comment='行驶证照片')
    car_type: Mapped[Optional[str]] = mapped_column(String(64), comment='车辆类型')
    car_brand: Mapped[Optional[str]] = mapped_column(String(64), comment='车辆品牌')
    car_model: Mapped[Optional[str]] = mapped_column(String(64), comment='车辆型号')
    car_head: Mapped[Optional[str]] = mapped_column(String(64), comment='车辆负责人')
    property_right: Mapped[Optional[str]] = mapped_column(String(64), comment='产权（public 公有，private 私有）')
    energy_type: Mapped[Optional[str]] = mapped_column(String(64), comment='能源类型（汽油，柴油，电）')
    buy_date: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='购买日期')
    vin_no: Mapped[Optional[str]] = mapped_column(String(64), comment='车架号')
    engine_o: Mapped[Optional[str]] = mapped_column(String(64), comment='发动机号')
    charging_type: Mapped[Optional[str]] = mapped_column(String(64), comment='计费类型')
    remark: Mapped[Optional[str]] = mapped_column(String(255), comment='备注')
    create_by: Mapped[Optional[str]] = mapped_column(String(32), comment='创建人')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='修改时间',
                                                                     server_default=func.now(), onupdate=func.now())
    update_by: Mapped[Optional[str]] = mapped_column(String(32), comment='修改人')
    # 新增2024-05-26
    seat_num: Mapped[Optional[int]] = mapped_column(Integer, comment='核定座位')
    fixed_asset_code: Mapped[Optional[str]] = mapped_column(String(64), comment='固定资产编号')
    car_number_color: Mapped[Optional[str]] = mapped_column(String(64), comment='车牌颜色')
    device_mode: Mapped[Optional[str]] = mapped_column(String(64), comment='设备模式')
    # 新增2024-05-28
    driver_id: Mapped[str] = mapped_column(String(32), comment='驾驶员id')

